/**
 *	Java Script code for AJAX working.
 *	Created By		: Atul Patel
 *  Creation Date	: 29-Nov-2006
 **/ 

function ajaxPost(url, xmlDocument , responseHandler){

		if(xmlDocument){

			var httpRequest = postXML(url,xmlDocument, responseHandler);
		}else {
			var httpRequest = postXML(url,null, responseHandler);
		}
	}

	function postXML(url,xmlDocument, responseHandler){

		var httpRequest;
		try {

			/*XMLHttpRequest object for IE Browser*/
			if(window.ActiveXObject){
			
				//alert("This is starting of IE");
				try{
				
					httpRequest = new ActiveXObject("MSXML2.XMLHTTP");
				
				}catch(e){
				
					try{
					httpRequest = new ActiveXObject("Mictosoft.XMLHTTP");
					
					}catch(e){
				
					alert("This is IE ["+e+"]");
					httpRequest = false ;
					}
				}
					
						
				
			}
			
			else {/*XMLHttpRequest object for Netscape Browser*/
			
				try{
					/*user_pref("capability.policy.XMLHttpRequestToAnySite.XMLHttpRequest.open","allAccess");
					user_pref("capability.policy.XMLHttpRequestToAnySite.sites", "http://localhost");
					user_pref("capability.policy.policynames", "XMLHttpRequestToAnySite");*/
					
					try {
				
						netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
					} catch (e) {
						alert("Permission UniversalBrowserRead denied.");
				   	}
			
					httpRequest = new XMLHttpRequest();
					
					
								
				}catch(e){
			
					alert("This is MOZILLA["+e+"]");
					httpRequest = false;
				}
			
			
				
			}

			httpRequest.open("GET",url,true);
			httpRequest.onreadystatechange = function(){

				
				if(httpRequest.readyState == 4){

					if(httpRequest.status == 200){

						responseHandler(httpRequest);
					}else{
						alert("There was a problem in retrieving the data:\n"+ httpRequest.statusText);
					}
				}
			};

			httpRequest.send(xmlDocument); /* Send data to the server*/
			

		}catch(e){

			alert("Can't post data ["+e+"]");
			return null;
		}
	}



	function serializeXML(xmlDocument){

		var firefox = document.getElementById && !document.all;
		/* For Netscape browser */
		if(firefox){

			var xmlSerialiazer ;
			try{
				xmlSerialiazer = new XMLSerializer();
				return xmlSerialiazer.serializeToString(xmlDocument);
			}catch(e){
				alert("Can't serialize XML document.");
				return null;
			}
		}else{/* For IE browser */
			return xmlDocument.xml;
		}
	}


	/*
	 @ function to create XML document from string
	 */

	function createXMLFromString(string){

		var firefox = document.getElementById && !document.all;

		/* For Netscape browser*/
		if(firefox){
			var xmlParser, xmlDocument;
			try{
				xmlParser = new DOMParser();
				xmlDocument = xmlParser.parseFromString(string,"text/xml");
				return xmlDocument;
			}catch(e){
				alert("[Can't create XML document .] "+e);
				return null;
			}

		}else {/* For IE browser*/
			var xmlDocument;
			try{
				xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
				xmlDocument.async = false;
				xmlDocument.loadXML(string);
				return xmlDocument;
			}catch(e){
				alert("[Can't create XML document .] "+e);
				return null;
			}
		}
	}

	/*
	 @ function to create cross-browser XMLHttp objects
	 */
	function createXMLHttp(){
		if(typeof XMLHttpRequest != 'undefiend'){ /*XMLHttpRequest object for Netscape Browser */

			return new XMLHttpRequest;

		}else if(windoe.ActiveXObject){/*XMLHttpRequest object for IE Browser		*/

			var aVersions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
			for (var i=0; i< aVersions.length; i++){
				try{
					var oXmlHttp = new ActiveXObject(aVersions[i]);
					return oXmlHttp;
				}catch(oError){
				}
			}
		}
		throw new Error("XMLHttp object could not be created");
	}

	/*
	 @ function to create latest version of XML DOM for IE browser
	 */
	function createDocument(){
		var aVersions = ["MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XmlDom"];

		for(var i=0; i< aVersions.length; i++){
			try{
				var oXmlDom = new ActiveXObject(aVersions[i]);
				return oXmlDom;
			}catch(oError){
			}
		}
		throw new Error("MSXML is not installed");
	}